﻿using Host.Domain;
using Host.InfrasIntructure.Interface;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Host.InfrasIntructure.Implement
{
    public  class EFCoreSensorDataRepository : BaseRepository<SensorData>, IEFCoreSensorDataRepository
    {
        private readonly HostDbContext _dbContext;

        public EFCoreSensorDataRepository(HostDbContext dbContext) : base(dbContext)
        {
            _dbContext = dbContext;
        }

        public async Task<SensorData> GetLatestByStationIdAsync(int stationId)
        {
            return await _dbContext.Set<SensorData>().Where(s => s.StationId == stationId).OrderByDescending(s => s.Timestamp).FirstOrDefaultAsync();
        }

        public async Task<List<SensorData>> GetByDateRangeAndStationIdAsync(int stationId, DateTime startDate, DateTime endDate)
        {
            return await _dbContext.Set<SensorData>().Where(s => s.StationId == stationId && s.Timestamp >= startDate && s.Timestamp <= endDate).ToListAsync();
        }
    }
}
